package com.xmler.plugin.adbrocket.adb

import com.android.ddmlib.AndroidDebugBridge
import com.android.ddmlib.IDevice
import com.intellij.openapi.project.Project
import org.jetbrains.android.sdk.AndroidSdkUtils

interface Bridge {
    fun isReady(): Boolean
    fun cnnectedDevices(): List<IDevice>
}

class BridgeImpl(private val project: Project): Bridge {
    private val androidBridge: AndroidDebugBridge?
        get() = AndroidSdkUtils.getDebugBridge(project)


    val mRealBridge: AndroidDebugBridge by lazy { androidBridge!! }

    override fun isReady(): Boolean {
        return androidBridge?.let {
            it.isConnected && it.hasInitialDeviceList()
        } ?: false
    }

    override fun cnnectedDevices(): List<IDevice> {
        return androidBridge?.devices?.asList() ?: emptyList()
    }

}